/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.shift.dao;

import bpmlab.shift.dao.service.GenericDAO;
import bpmlab.shift.entity.Aplicacao;
import bpmlab.shift.entity.Formulacao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
/**
 *
 * @author Mikael Lima
 */
public class FormulacaoDAOJpa {
    
    private final GenericDAO<Formulacao> dao = DAOFactory.criarGenericDAO(Formulacao.class);

    public void salvar(Formulacao o) throws DAOException {
        dao.salvar(o);
    }

    public void excluir(Formulacao o) throws DAOException {
        dao.excluir(o);
    }

    public Formulacao obter(Object id) throws DAOException {
        return dao.obter(id);
    }

    public List<Formulacao> obterTodos() throws DAOException {
        return dao.obterTodos();
    }
    
    public List<Formulacao> obterPorAplicacao(Aplicacao aplicacao) throws DAOException {
        EntityManager em = JpaUtil.getEntityManager();
        String jpql = "SELECT f FROM Formulacao f WHERE f.aplicacaoFormulacao = :aplicacao";
        Query q = em.createQuery(jpql)
                .setParameter("aplicacao", aplicacao);
        List<Formulacao> resultado = q.getResultList();
        return resultado;
    }
    
}
